package web.security;

import core.entity.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author MG
 * @since 29.04.2014
 */
public class AppUserDetails implements UserDetails {

    User user;
    List<GrantedAuthority> roles = new ArrayList<>();

    public AppUserDetails(User user) {
        this.user = user;

        /*for (UserRole userRole : user.getRoles()) {
            roles.add(new SimpleGrantedAuthority(userRole.getName()));
        }*/
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roles;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public User getUser() {
        return user;
    }
}
